package com.jr.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jr.pojo.*;
import com.jr.service.PostsService;
import com.jr.util.ResultObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

@RestController
@RequestMapping("/Posts/")
public class PostsController {
    @Autowired
    private PostsService postsService;

    @RequestMapping("SelectAll")
    public ArrayList<PostPname> selectAll(){
        return postsService.selectAll();
    }

    @RequestMapping("SelectShow")
    public ArrayList<EnterpriseAndPosts> selectShow(){

        return postsService.selectShow();
    }

    @RequestMapping("SelectJob")
    public ArrayList<SearchJob> selectJob(SearchJob searchJob){

        return postsService.selectJob(searchJob);
    }

    @Autowired
    private ResultObject resultObject;

    @RequestMapping("selectbystatus")
    public PageInfo<EntAndPosts> selectbystatus(EntAndPosts entAndPosts) {
        entAndPosts.setApply("已申请");
        if (entAndPosts.getPageNum()==null){
            PageHelper.startPage(1,3);
        }else{
            PageHelper.startPage(entAndPosts.getPageNum(),3);
        }

        ArrayList<EntAndPosts> entandpost = postsService.selectByStatus(entAndPosts);
        PageInfo pageInfo=new PageInfo(entandpost);
        return pageInfo;
    }
    @RequestMapping("selectlike")
    public PageInfo<EntAndPosts> selectLike(EntAndPosts entAndPosts){
        if (entAndPosts.getPageNum()==null){
            PageHelper.startPage(1,3);
        }else{
            PageHelper.startPage(entAndPosts.getPageNum(),3);
        }

        ArrayList<EntAndPosts> entandpost = postsService.selectLike(entAndPosts);
        PageInfo pageInfo=new PageInfo(entandpost);
        return pageInfo;
    }
    @RequestMapping("update1")
    public ResultObject update1(UserAndPosition userAndPosition){
        boolean b = postsService.updateApply(userAndPosition);
        if (b){
            resultObject.setStatus(400);
            resultObject.setResult("取消成功");
        }else{
            resultObject.setStatus(404);
            resultObject.setResult("取消失败");
        }
        return resultObject;
    }

    @RequestMapping("SelectPostByEid")
    public ArrayList<ShowPost> selectPostByEid(ShowPost showPost){
        return postsService.selectPostByEid(showPost);
    }

    @RequestMapping("SelectAllByEid")
    public ArrayList<ShowPost> selectAllByEid(ShowPost showPost){

        return postsService.selectAllByPname(showPost);
    }

    @RequestMapping("updateConcern")
    public ResultObject updateConcern(ShowPost showPost){
        boolean b = postsService.updateConcern(showPost);
        if (b){
            resultObject.setStatus(400);
            resultObject.setResult("取消成功");
        }else{
            resultObject.setStatus(404);
            resultObject.setResult("取消失败");
        }
        return resultObject;
    }
    @RequestMapping("update2")
    public ResultObject update2(ShowPost showPost){
        boolean b = postsService.updateApply1(showPost);
        if (b){
            resultObject.setStatus(400);
            resultObject.setResult("取消成功");
        }else{
            resultObject.setStatus(404);
            resultObject.setResult("取消失败");
        }
        return resultObject;
    }
}
